﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoCooker4
{
    public delegate void CookStartedReply();
    public delegate void CookProgressingReply();
    public delegate int CookCompletedReply();

    class AutoCooker4
    {
        // enent关键字在委托的外边包装了一个 property，仅让 C#客户通过 += 和 -=操作符来添加和移除，不能直接激发事件。
        public event CookStartedReply started;
        public event CookProgressingReply progressing;
        public event CookCompletedReply completed;

        public void DoCook()
        {
            Console.WriteLine("AutoCooker start to cook");
            if (started != null) started();

            Console.WriteLine("AutoCooker is cooking");
            if (progressing != null) progressing();

            Console.WriteLine("AutoCooker finish to Cook");
            if (completed != null)
            {
                int grade = completed();
                Console.WriteLine("My appetite is {0} %", grade);
            }
        }
    }
}
